<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\helpers\ArrayHelper;
use common\models\Category;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\CategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Categories');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-index">
    <p>
        <?= Html::a(Yii::t('app', 'Create Category'), ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?php Pjax::begin(); ?>    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            [
                'attribute' => 'pid',
                'value' => function ($model) {
                    return $model->p->name;
                },
                'filter' => Category::Select($searchModel->pid, 'CategorySearch[pid]', 'class="form-control"'),
            ],
            'name',
            'sort_no',
            'create_time:datetime',

            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'template' => '{update}',
                'buttons' => [

                    'update' => function ($url, $model, $key) {
                        return Html::a('编辑', $url);
                    },
                ],
                'headerOptions' => ['width' => 'auto'],
            ],
        ],
    ]); ?>
    <?php Pjax::end(); ?></div>
